import { Entry } from "@/types/intro";
import { request } from "../request";
import { getStore } from "@/store";

export const createEntry = async (data: { title: string; content: string }) => {
    try {
        return await request<Entry>("/user/richText/save", data);
    } catch (err) {
        throw err;
    }
};

export const getEntries = async () => {
    try {
        const res = await request<Entry[]>("/user/richText/get-all", null);
        getStore("entry").setEntries(res);
    } catch (err) {
        throw err;
    }
};

export const updateEntry = async (title: string, content: string) => {
    try {
        return await request("/user/richText/update", {
            title: title,
            content: content,
        });
    } catch (err) {
        throw err;
    }
};

export const deleteEntry = async (id: string) => {
    try {
        return await request("/user/richText/delete", {
            id: id,
        });
    } catch (err) {
        throw err;
    }
};
